/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.NVQL;

import DAO.CTPXuatKhoDao;
import GUI.TOOL.ExcelOpener;
import DAO.HoaDonDao;
import DAO.NhaCungCapDao;
import DAO.NhanVienDao;
import DAO.PXuatKhoDao;
import DAO.SanPhamDao;
import GUI.TOOL.XuatExcel;
import GUI.Var;
import POJO.CTPXuatKho;
import POJO.KhachHang;
import POJO.NhanVien;
import POJO.PXuatKho;
import POJO.SanPham;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Hồng
 */
public class frXemPhieuXuatKho extends javax.swing.JInternalFrame {

	private DefaultComboBoxModel cbModel;
	private DefaultTableModel model = null;
	private DefaultTableModel model2 = null;
	private int SD;
	private int TSD;// tong so dong trong bang hoa don
	private int THT; //trang hiện tại
	int stt = 1;

	private void loadCbNV() {

		NhanVienDao dao = new NhanVienDao();

		ArrayList<NhanVien> ds = dao.layDanhSach();
		NhanVien nv = new NhanVien(0, "ALL", "", "", 0, 0);
		this.cbModel.addElement(nv);
		for (int i = 0; i < ds.size(); i++) {
			this.cbModel.addElement(ds.get(i));

		}
		if (cbModel.getSize() > 0) {
			cbModel.setSelectedItem(cbModel.getElementAt(0));
		}
	}

	public void DefaultFrom() {
		model2 = new DefaultTableModel();
		this.model2.addColumn("Số PN");
		this.model2.addColumn("Ngày xuất");
		this.model2.addColumn("NV phụ trách");

		model = new DefaultTableModel();
		this.model.addColumn("Mã PX");
		this.model.addColumn("Ngày");
		this.model.addColumn("NV");
		this.model.addColumn("HD");
	}

	private void load(int soDong, int trangSo) {
		int manv = jcbNV.getSelectedIndex();
		if (manv == 0) {
			loadAll(SD, THT);

		} else {
			ArrayList<PXuatKho> dsPXuatKho = null;

			try {

				dsPXuatKho = PXuatKhoDao.layDanhSachByNhanVienPhanTrang(manv, soDong, trangSo);
				//dsPNhapKho= PNhapKhoDao.layDanhSach();
			} catch (Exception e) {
			}

			NhaCungCapDao dao = new NhaCungCapDao();
			NhanVienDao nvdao = new NhanVienDao();
			DefaultFrom();
			//int stt = 1;
			for (PXuatKho pnk : dsPXuatKho) {
				manv = pnk.getMaNVPhuTrach();
				NhanVien nv = nvdao.layByMa(manv);
				Object[] items = new Object[]{
					pnk.getMaPXK(),
					Var.hienThiNgayVN(pnk.getNgayXuat()),
					//pnk.getMaNVPhuTrach()
					nv.getTenNV(),};
				Object[] items1 = new Object[]{
					pnk.getMaPXK(),
					Var.hienThiNgayVN(pnk.getNgayXuat()),
					pnk.getMaNVPhuTrach(),
					pnk.getMaHD(),};
				model.addRow(items1);
				model2.addRow(items);
				stt++;

			}
			jtbPXK.setModel(model2);

			int[] va = {20, 20, 60};
			int[] pt = new int[3];
			for (int l = 0; l < 3; l++) {
				pt[l] = jtbPXK.getWidth() * va[l] / 100;
				jtbPXK.getColumnModel().getColumn(l).setPreferredWidth(pt[l]);

			}
		}
	}

	private void loadAll(int soDong, int trangSo) {
		ArrayList<PXuatKho> dsPXuatKho = PXuatKhoDao.layDanhSachPhanTrang(soDong, trangSo);
		String[] columns = new String[]{"Mã phiếu nhập", "Ngày nhập", "NV phụ trách"};

		NhanVienDao nvdao = new NhanVienDao();
		DefaultFrom();
		//int stt = 1;
		for (PXuatKho px : dsPXuatKho) {
			int manv = px.getMaNVPhuTrach();
			NhanVien nv = nvdao.layByMa(manv);
			Object[] items = new Object[]{
				px.getMaPXK(),
				Var.hienThiNgayVN(px.getNgayXuat()),
				//cc.getTenNCC()
				//pnk.getMaNVPhuTrach()
				nv.getTenNV(),};
			Object[] items1 = new Object[]{
				px.getMaPXK(),
				Var.hienThiNgayVN(px.getNgayXuat()),
				px.getMaNVPhuTrach(),
				px.getMaHD()};
			model.addRow(items1);
			model2.addRow(items);
			//stt++;
		}
		jtbPXK.setModel(model2);
		int[] va = {20, 20, 60};
		int[] pt = new int[3];
		for (int l = 0; l < 3; l++) {
			pt[l] = jtbPXK.getWidth() * va[l] / 100;
			jtbPXK.getColumnModel().getColumn(l).setPreferredWidth(pt[l]);

		}
	}

	public void loadCT(int dong) {
		// load tren text
		int soPNK = (Integer) model.getValueAt(dong, 0);
		String NgayXuat = (String) model2.getValueAt(dong, 1);
		int manv = (Integer) model.getValueAt(dong, 2);
		int mahd = (Integer) model.getValueAt(dong, 3);

		NhanVienDao nv = new NhanVienDao();
		NhanVien dsnv = nv.layByMa(manv);
		HoaDonDao hddao = new HoaDonDao();
		KhachHang kh = hddao.layKhachHangByMaHoaDon(mahd);

		jtxtMaPX.setText(String.valueOf(soPNK));
		jtxtNgay.setText(NgayXuat);
		jtxtKH.setText(kh.getTenKH());
		jtxtNV.setText(dsnv.getTenNV());
		jtxtHD.setText(String.valueOf(mahd));

		// load luoi chi tiet 

		SanPhamDao dao = new SanPhamDao();
		SanPham sp = new SanPham();
		ArrayList<CTPXuatKho> dsCTPXuatKho = CTPXuatKhoDao.layDanhSachByMaPX(soPNK);
		String[] columns = new String[]{"STT", "Mã sản phẩm", "Tên sản phẩm", "Số lượng"};
		DefaultTableModel model = new DefaultTableModel(null, columns);
		int t = 1;
		double gia = 0;
		for (CTPXuatKho ctpnk : dsCTPXuatKho) {
			sp = dao.layDanhSachByMaSP(ctpnk.getMaSP());
			Object[] items = new Object[]{
				t,
				ctpnk.getMaSP(),
				sp.getTenSP(),
				ctpnk.getSoLuong(),};
			t++;
			model.addRow(items);

		}

		jtbCTPXK.setModel(model);
		int[] va = {10, 10, 30, 25, 25};
		int[] pt = new int[4];
		for (int l = 0; l < 4; l++) {
			pt[l] = jtbCTPXK.getWidth() * va[l] / 100;
			jtbCTPXK.getColumnModel().getColumn(l).setPreferredWidth(pt[l]);

		}
	}

	private void setTxt() {
		lbPhanTrang.setText(Integer.toString(THT + 1) + "/" + Integer.toString(TSD / SD + 1));
	}

	private int soDongDuLieu() {
		int tmp = 0;
		PXuatKhoDao dao = new PXuatKhoDao();
		try {
			tmp = dao.laySoDong();
		} catch (Exception e) {
		}
		return tmp;
	}

	/**
	 * Creates new form frXemPhieuXuatKho
	 */
	public frXemPhieuXuatKho() {
		initComponents();
		TSD = soDongDuLieu();
		THT = 0;

		this.cbModel = new DefaultComboBoxModel();
		this.jcbNV.setModel(cbModel);
		loadCbNV();

		SD = 20;
		loadAll(SD, THT);
		load(SD, THT);
//                if (model.getRowCount() > 0) {			
//			loadCT(0);
//		}

		setTxt();
	}

	/**
	 * This method is called from within the constructor to initialize the
	 * form. WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
       // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
       private void initComponents() {

              jPanel3 = new javax.swing.JPanel();
              jPanel4 = new javax.swing.JPanel();
              jScrollPane2 = new javax.swing.JScrollPane();
              jtbPXK = new javax.swing.JTable();
              jLabel7 = new javax.swing.JLabel();
              jcbNV = new javax.swing.JComboBox();
              jPanel9 = new javax.swing.JPanel();
              jButton3 = new javax.swing.JButton();
              jButton1 = new javax.swing.JButton();
              jButton5 = new javax.swing.JButton();
              jButton4 = new javax.swing.JButton();
              lbPhanTrang = new javax.swing.JLabel();
              jPanel6 = new javax.swing.JPanel();
              jPanel8 = new javax.swing.JPanel();
              jLabel2 = new javax.swing.JLabel();
              jtxtMaPX = new javax.swing.JTextField();
              jLabel3 = new javax.swing.JLabel();
              jtxtNgay = new javax.swing.JTextField();
              jLabel4 = new javax.swing.JLabel();
              jtxtKH = new javax.swing.JTextField();
              jLabel5 = new javax.swing.JLabel();
              jtxtNV = new javax.swing.JTextField();
              jLabel6 = new javax.swing.JLabel();
              jtxtHD = new javax.swing.JTextField();
              jPanel7 = new javax.swing.JPanel();
              jScrollPane1 = new javax.swing.JScrollPane();
              jtbCTPXK = new javax.swing.JTable();
              jPanel1 = new javax.swing.JPanel();
              jLabel1 = new javax.swing.JLabel();
              jPanel10 = new javax.swing.JPanel();
              jbtnLapBaoCao2 = new javax.swing.JButton();
              jButton15 = new javax.swing.JButton();
              jLabel8 = new javax.swing.JLabel();
              jLabel9 = new javax.swing.JLabel();
              jLabel10 = new javax.swing.JLabel();
              lbTSSPDX = new javax.swing.JLabel();
              lbTongSoLuong = new javax.swing.JLabel();
              jlbTSLanXuatKho = new javax.swing.JLabel();

              setClosable(true);
              setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
              setIconifiable(true);
              setMaximizable(true);
              setResizable(true);

              jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách phiếu xuất kho"));
              jPanel4.setToolTipText("");

              jtbPXK.setModel(new javax.swing.table.DefaultTableModel(
                     new Object [][] {

                     },
                     new String [] {
                            "Số phiếu xuất", "Ngày xuất", "NV phụ trách"
                     }
              ));
              jtbPXK.addMouseListener(new java.awt.event.MouseAdapter() {
                     public void mouseClicked(java.awt.event.MouseEvent evt) {
                            jtbPXKMouseClicked(evt);
                     }
              });
              jScrollPane2.setViewportView(jtbPXK);

              jLabel7.setText("Chọn nhân viên:");

              jcbNV.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ALL", "Item 2", "Item 3", "Item 4" }));
              jcbNV.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jcbNVActionPerformed(evt);
                     }
              });

              jButton3.setText("|<");
              jButton3.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton3ActionPerformed(evt);
                     }
              });

              jButton1.setText("<");
              jButton1.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                     }
              });

              jButton5.setText(">|");
              jButton5.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton5ActionPerformed(evt);
                     }
              });

              jButton4.setText(">");
              jButton4.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton4ActionPerformed(evt);
                     }
              });

              lbPhanTrang.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              lbPhanTrang.setText("0");

              javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
              jPanel9.setLayout(jPanel9Layout);
              jPanel9Layout.setHorizontalGroup(
                     jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel9Layout.createSequentialGroup()
                            .addContainerGap(82, Short.MAX_VALUE)
                            .addComponent(jButton3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbPhanTrang)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton5)
                            .addContainerGap(82, Short.MAX_VALUE))
              );
              jPanel9Layout.setVerticalGroup(
                     jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                            .addGap(0, 0, Short.MAX_VALUE)
                            .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jButton3)
                                   .addComponent(jButton1)
                                   .addComponent(jButton5)
                                   .addComponent(jButton4)
                                   .addComponent(lbPhanTrang)))
              );

              javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
              jPanel4.setLayout(jPanel4Layout);
              jPanel4Layout.setHorizontalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel4Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel7)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jcbNV, 0, 260, Short.MAX_VALUE)
                            .addContainerGap())
                     .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                     .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              );
              jPanel4Layout.setVerticalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel7)
                                   .addComponent(jcbNV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
              );

              jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin phiếu xuất kho"));

              jLabel2.setText("Số phiếu xuất kho:");

              jtxtMaPX.setEditable(false);

              jLabel3.setText("Ngày xuất:");

              jtxtNgay.setEditable(false);

              jLabel4.setText("Khách hàng:");

              jtxtKH.setEditable(false);

              jLabel5.setText("Nhân viên phụ trách:");

              jtxtNV.setEditable(false);

              jLabel6.setText("Xuất cho hóa đơn số:");

              jtxtHD.setEditable(false);

              javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
              jPanel8.setLayout(jPanel8Layout);
              jPanel8Layout.setHorizontalGroup(
                     jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel8Layout.createSequentialGroup()
                            .addGap(12, 12, 12)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jtxtKH, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                                   .addComponent(jtxtNgay, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                                   .addComponent(jtxtHD)
                                   .addComponent(jtxtNV)
                                   .addComponent(jtxtMaPX))
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel8Layout.setVerticalGroup(
                     jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel8Layout.createSequentialGroup()
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel2)
                                   .addComponent(jtxtMaPX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel3)
                                   .addComponent(jtxtNgay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel4)
                                   .addComponent(jtxtKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel5)
                                   .addComponent(jtxtNV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel6)
                                   .addComponent(jtxtHD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(0, 0, Short.MAX_VALUE))
              );

              jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Chi tiết phiếu xuất kho"));

              jtbCTPXK.setModel(new javax.swing.table.DefaultTableModel(
                     new Object [][] {

                     },
                     new String [] {
                            "STT", "Mã sản phẩm", "Tên sản phẩm", "Số lượng"
                     }
              ));
              jScrollPane1.setViewportView(jtbCTPXK);

              javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
              jPanel7.setLayout(jPanel7Layout);
              jPanel7Layout.setHorizontalGroup(
                     jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
              );
              jPanel7Layout.setVerticalGroup(
                     jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
              );

              javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
              jPanel6.setLayout(jPanel6Layout);
              jPanel6Layout.setHorizontalGroup(
                     jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                     .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              );
              jPanel6Layout.setVerticalGroup(
                     jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel6Layout.createSequentialGroup()
                            .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );

              javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
              jPanel3.setLayout(jPanel3Layout);
              jPanel3Layout.setHorizontalGroup(
                     jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel3Layout.setVerticalGroup(
                     jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                     .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              );

              jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
              jLabel1.setText("XEM PHIẾU XUẤT KHO");

              javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
              jPanel1.setLayout(jPanel1Layout);
              jPanel1Layout.setHorizontalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel1Layout.setVerticalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(0, 0, Short.MAX_VALUE))
              );

              jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Chức năng"));

              jbtnLapBaoCao2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jbtnLapBaoCao2.setText("Lập báo cáo");
              jbtnLapBaoCao2.setToolTipText("gọi lập phiếu nhập kho");
              jbtnLapBaoCao2.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnLapBaoCao2ActionPerformed(evt);
                     }
              });

              jButton15.setText("Lưu ra Excel");
              jButton15.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton15ActionPerformed(evt);
                     }
              });

              jLabel8.setText("Tổng số phiếu xuất");

              jLabel9.setText("Từ ngày:");

              jLabel10.setText("Đến ngày:");

              lbTSSPDX.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              lbTSSPDX.setText("0");

              lbTongSoLuong.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              lbTongSoLuong.setText("0");

              jlbTSLanXuatKho.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jlbTSLanXuatKho.setText("0");

              javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
              jPanel10.setLayout(jPanel10Layout);
              jPanel10Layout.setHorizontalGroup(
                     jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel10Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jbtnLapBaoCao2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel8)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbTSSPDX)
                            .addGap(56, 56, 56)
                            .addComponent(jLabel9)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbTongSoLuong)
                            .addGap(49, 49, 49)
                            .addComponent(jLabel10)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jlbTSLanXuatKho)
                            .addContainerGap(170, Short.MAX_VALUE))
              );
              jPanel10Layout.setVerticalGroup(
                     jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbtnLapBaoCao2)
                            .addComponent(jButton15)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10)
                            .addComponent(lbTSSPDX)
                            .addComponent(lbTongSoLuong)
                            .addComponent(jlbTSLanXuatKho))
              );

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGap(0, 0, 0))
              );
              layout.setVerticalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0))
              );

              pack();
       }// </editor-fold>//GEN-END:initComponents

       private void jbtnLapBaoCao2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnLapBaoCao2ActionPerformed
		// TODO add your handling code here:
		//int mnv =Var.NV.getMaNV();

		//load(mnv);
		int soluong = model.getRowCount();//CTHoaDonDao.TongSanPhamDaBanTrongNgay(mnv);
		lbTSSPDX.setText(String.valueOf(soluong));
		String ngaybd = model.getValueAt(0, 1).toString();//CTHoaDonDao.TongTienDaBanTrongNgay(mnv);
		lbTongSoLuong.setText(String.valueOf(ngaybd));
		String ngaykt = model.getValueAt(Integer.valueOf(model.getRowCount()) - 1, 1).toString();//CTHoaDonDao.TongTienDaThuTrongNgay(mnv);
		jlbTSLanXuatKho.setText(String.valueOf(ngaykt));

       }//GEN-LAST:event_jbtnLapBaoCao2ActionPerformed

       private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
		// TODO add your handling code here:
		// ve dau tien
		THT = 0;
		load(SD, THT);
		loadAll(SD, THT);
		setTxt();
       }//GEN-LAST:event_jButton3ActionPerformed

       private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
		// TODO add your handling code here:
		//ve trang truoc
		if (THT != 0) {
			THT -= 1;
			load(SD, THT);
			loadAll(SD, THT);
		}
		setTxt();
       }//GEN-LAST:event_jButton1ActionPerformed

       private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
		// TODO add your handling code here:
		// ve cuoi
		THT = TSD / SD;
		load(SD, THT);
		loadAll(SD, THT);
		setTxt();
       }//GEN-LAST:event_jButton5ActionPerformed

       private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
		if (THT < TSD / SD) {
			THT += 1;
			load(SD, THT);
			loadAll(SD, THT);
		}
		setTxt();
       }//GEN-LAST:event_jButton4ActionPerformed

    private void jcbNVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbNVActionPerformed
	    load(SD, 0);
	    jtxtHD.setText(null);
	    jtxtKH.setText(null);
	    jtxtMaPX.setText(null);
	    jtxtNV.setText(null);
	    jtxtNgay.setText(null);
	    String[] columns = new String[]{"STT", "Mã sản phẩm", "Tên sản phẩm", "Số lượng"};
	    DefaultTableModel model = new DefaultTableModel(null, columns);
	    jtbCTPXK.setModel(model);
    }//GEN-LAST:event_jcbNVActionPerformed

    private void jtbPXKMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtbPXKMouseClicked
	    int dong = this.jtbPXK.getSelectedRow();
	    loadCT(dong);
    }//GEN-LAST:event_jtbPXKMouseClicked

       private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
		// TODO add your handling code here:
		try {
			//     Note that i'm actually saving the file first
			XuatExcel exp = new XuatExcel();
			File file = new File("BaoCaoXuatKho.xls");
			exp.exportTable(jtbPXK, file);

			ExcelOpener opn = new ExcelOpener();
			opn.openTable(file);
		} catch (IOException ex) {
			System.out.println(ex.getMessage());
			ex.printStackTrace();
		}
       }//GEN-LAST:event_jButton15ActionPerformed
       // Variables declaration - do not modify//GEN-BEGIN:variables
       private javax.swing.JButton jButton1;
       private javax.swing.JButton jButton15;
       private javax.swing.JButton jButton3;
       private javax.swing.JButton jButton4;
       private javax.swing.JButton jButton5;
       private javax.swing.JLabel jLabel1;
       private javax.swing.JLabel jLabel10;
       private javax.swing.JLabel jLabel2;
       private javax.swing.JLabel jLabel3;
       private javax.swing.JLabel jLabel4;
       private javax.swing.JLabel jLabel5;
       private javax.swing.JLabel jLabel6;
       private javax.swing.JLabel jLabel7;
       private javax.swing.JLabel jLabel8;
       private javax.swing.JLabel jLabel9;
       private javax.swing.JPanel jPanel1;
       private javax.swing.JPanel jPanel10;
       private javax.swing.JPanel jPanel3;
       private javax.swing.JPanel jPanel4;
       private javax.swing.JPanel jPanel6;
       private javax.swing.JPanel jPanel7;
       private javax.swing.JPanel jPanel8;
       private javax.swing.JPanel jPanel9;
       private javax.swing.JScrollPane jScrollPane1;
       private javax.swing.JScrollPane jScrollPane2;
       private javax.swing.JButton jbtnLapBaoCao2;
       private javax.swing.JComboBox jcbNV;
       private javax.swing.JLabel jlbTSLanXuatKho;
       private javax.swing.JTable jtbCTPXK;
       private javax.swing.JTable jtbPXK;
       private javax.swing.JTextField jtxtHD;
       private javax.swing.JTextField jtxtKH;
       private javax.swing.JTextField jtxtMaPX;
       private javax.swing.JTextField jtxtNV;
       private javax.swing.JTextField jtxtNgay;
       private javax.swing.JLabel lbPhanTrang;
       private javax.swing.JLabel lbTSSPDX;
       private javax.swing.JLabel lbTongSoLuong;
       // End of variables declaration//GEN-END:variables
}
